package com.piedra.socket;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class GetBaidu {
	public static void main(String[] args) {
		new GetBaidu().init();
	}
	
	private void init(){
		try {
			URL url = new URL("http://www.baidu.com");
			URLConnection conn = url.openConnection();
			conn.connect();
			InputStream in = conn.getInputStream();
			
			byte [] buf = new byte[1024];
			int len = 0;
			while((len = in.read(buf)) != -1){
				System.out.println(new String(buf,0,len));
			}
			
		} catch(MalformedURLException e){
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
